package com.server.libs.ret;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class ExHandler {

    /**
     * 处理自定义异常
     *
     */
    @ExceptionHandler(value = RE.class)
    @ResponseBody
    public R<?> bizExceptionHandler(RE e) {
//        log.warn(e.toString());
        return new R<>(e.errorMsg,e.errorCode,false);
    }

    /**
     * 处理其他异常
     *
     */
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public R<?> exceptionHandler(Exception e) {
        log.warn(e.toString());
        e.printStackTrace();
        return new R<>(e.toString(),400,false);
    }
}
